package com.itheima.web.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/resp3")
public class ResponseDemo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应格式
        //如果页面出现下载，则表示这行代码存在问题
        resp.setContentType("text/html;charset=utf-8");
        //resp.setHeader("content-Type","text/html;charset=utf-8");
        //获取字符输出流
        //流无需手动关闭
        PrintWriter writer = resp.getWriter();
        //写入数据
        writer.write("<h1>嗨喽</h1>");
        writer.write("<font color='green'>你好</font>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
